import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTextFormat } from "../../../../common/GTextFormat";
import { ColorConfig } from "../../../resource/ColorConfig";
import { BaseItem } from "../../common/BaseItem";
import { Language } from "../../../../../extend/language/Language";
import { TOpenRechargeGiftBag } from "../../../../../Message/Db/Tables/TOpenRechargeGiftBag";
import { ItemData } from "../../../resource/info/ItemData";
import { EffectManager } from "../../../manager/EffectManager";
import { DataEvent } from "../../../events/DataEvent";
import { BrowerUtil } from "../../../../../com/gengine/utils/BrowerUtil";
import { ParamsConst } from "../../../../common/global/ParamsConst";
import { Cache } from "../../../cache/Cache";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class RechargeGiftBagItem
    
    export  class RechargeGiftBagItem /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._numChArr = ["一", "二", "三", "四", "五", "六", "七"];
            this._glowYellow = new Object /* flash.filters.GlowFilter */(16776960, 1, 3, 3, 5);
            this.init();
            addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStageHandler);
            return;
        }

        /* internal  */onAddToStageHandler(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.addEventListener(EventName.HavePay, this.onMoneyUpdateHandler);
            Dispatcher.addEventListener(EventName.DailyGiftInfoRes, this.onDailyGiftInfoResHandler);
            addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onRemoveFromStageHandler);
            this.onMoneyUpdateHandler();
            return;
        }

        /* internal  */onRemoveFromStageHandler(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.removeEventListener(EventName.HavePay, this.onMoneyUpdateHandler);
            Dispatcher.removeEventListener(EventName.DailyGiftInfoRes, this.onDailyGiftInfoResHandler);
            removeEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onRemoveFromStageHandler);
            return;
        }

        /* internal  */init(): void
        {
            this._bg = ObjCreate.createBg(0, 0, 90, 150, this, ImagesConst.RechargeBottom);
            var loc1=new GTextFormat("", 12, 16776960, null, null, null, null, null, flash.text.TextFormatAlign.CENTER);
            this._numTxt = ObjCreate.createTextField("", 0, 5, 90, 20, this, loc1);
            var loc2=new GTextFormat("", 12, ColorConfig.instance.getItemColor(4).intColor, true, null, null, null, null, flash.text.TextFormatAlign.CENTER);
            this._nameBg = ObjCreate.createBg(0, 25, 80, 20, this, ImagesConst.FightingStrgBg);
            this._nameTxt = ObjCreate.createTextField("", 0, 25, 90, 20, this, loc2);
            this._itemBg = ObjCreate.createBg(14, 50, 64, 64, this, ImagesConst.PackItemBg);
            this._baseItem = new BaseItem();
            this._baseItem.move(16, 52);
            this._baseItem.setSize(60, 60);
            this._baseItem.isDragAble = false;
            this._baseItem.isDropAble = false;
            addChild(this._baseItem);
            this._getBtn = ObjCreate.createGButton(Language.getString(20146), 20, 120, 50, 25, this, "ButtonRed");
            this._getBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGetBtnClickHandler);
            this._getBtn.enabled = false;
            return;
        }

        public updateData(arg1: TOpenRechargeGiftBag): void
        {
            this._info = arg1;
            this._numTxt.text = Language.getStringByParam(20147, this._numChArr[(arg1.code - 1)]);
            if (arg1.code != 1) 
            {
                if (arg1.code != 2) 
                {
                    this._nameTxt.text = Language.getStringByParam(20151, arg1.target);
                }
                else 
                {
                    this._nameTxt.text = Language.getString(20150);
                }
            }
            else 
            {
                this._pwidth = 115;
                this._numTxt.width = 115;
                this._nameTxt.width = 115;
                this._bg.width = 115;
                this._nameBg.width = 110;
                this._nameTxt.text = Language.getString(20148);
                this._getBtn.x = 5;
                this._itemBg.x = 26;
                this._baseItem.x = 28;
                this._exchangeBtn = ObjCreate.createGButton(Language.getString(20149), 60, 120, 50, 25, this, "ButtonRedMini");
                this._exchangeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onExchangeBtnClickHandler);
            }
            this._baseItem.itemData = new ItemData(arg1.itemCode);
            this.onMoneyUpdateHandler();
            return;
        }

        public setGetBtn(arg1: Boolean): void
        {
            this._getBtn.enabled = arg1;
            if (!arg1) 
            {
                this._getBtn.label = Language.getString(20152);
                this._isHadGet = true;
                EffectManager.glowFilterUnReg(this._getBtn);
            }
            return;
        }

        /* internal  */onGetBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._info.code >= 3) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GetOpenRechargeGiftBag, this._info.code));
            }
            else if (this._info.code != 1) 
            {
                if (this._info.code == 2) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.NovicePackGet, 3));
                }
            }
            else 
            {
                BrowerUtil.getUrl(ParamsConst.instance.xskUrl);
            }
            return;
        }

        /* internal  */onExchangeBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.NoviceCardOpen));
            return;
        }

        /* internal  */onMoneyUpdateHandler(arg1: Object=null): void
        {
            var loc1=0;
            if (this._info.code == 1 && !Cache.instance.daily.promotionCardUsed) 
            {
                this._getBtn.enabled = true;
                EffectManager.glowFilterReg(this._getBtn, [this._glowYellow], 0.5, 6, 3, 0);
            }
            else if (this._info.code == 2 && !Cache.instance.daily.firstPayPackUsed && Cache.instance.role.recharge >= 1) 
            {
                this._getBtn.enabled = true;
                EffectManager.glowFilterReg(this._getBtn, [this._glowYellow], 0.5, 6, 3, 0);
            }
            else if (this._info.code >= 3) 
            {
                loc1 = Cache.instance.role.recharge;
                if (loc1 >= this._info.target && !this._isHadGet) 
                {
                    this._getBtn.enabled = true;
                    EffectManager.glowFilterReg(this._getBtn, [this._glowYellow], 0.5, 6, 3, 0);
                }
            }
            return;
        }

        /* internal  */onDailyGiftInfoResHandler(arg1: DataEvent): void
        {
            this.updateHadGetState();
            return;
        }

        public updateHadGetState(): void
        {
            if (this._info.code != 1) 
            {
                if (this._info.code == 2) 
                {
                    if (Cache.instance.daily.firstPayPackUsed) 
                    {
                        this.setGetBtn(false);
                    }
                }
            }
            else if (Cache.instance.daily.promotionCardUsed) 
            {
                this.setGetBtn(false);
            }
            return;
        }

        public setClickState(arg1: Boolean): void
        {
            if (this._gradientGlow == null) 
            {
                this._gradientGlow = new Object /* flash.filters.GradientGlowFilter */();
                this._gradientGlow.distance = 0;
                this._gradientGlow.angle = 45;
                this._gradientGlow.colors = [16777062, 16776960];
                this._gradientGlow.alphas = [0, 1];
                this._gradientGlow.ratios = [0, 255];
                this._gradientGlow.blurX = 5;
                this._gradientGlow.blurY = 5;
                this._gradientGlow.strength = 2;
                this._gradientGlow.quality = flash.filters.BitmapFilterQuality.HIGH;
                this._gradientGlow.type = flash.filters.BitmapFilterType.OUTER;
            }
            if (arg1 && this._gradientGlow) 
            {
                this.filters = [this._gradientGlow];
            }
            else 
            {
                this.filters = [];
            }
            return;
        }

        public setCanGetState(): void
        {
            var loc1=Cache.instance.role.recharge;
            if (loc1 >= this._info.target && !this._isHadGet && !(this._info.code == 1) && !(this._info.code == 2)) 
            {
                EffectManager.glowFilterReg(this._getBtn, [this._glowYellow], 0.5, 6, 3, 0);
                this._getBtn.enabled = true;
            }
            return;
        }

        public get pwidth(): int
        {
            return this._pwidth;
        }

        public get itemCode(): int
        {
            return this._info.itemCode;
        }

        public get value(): int
        {
            return this._info.value;
        }

        public get code(): int
        {
            return this._info.code;
        }

        public get numStr(): string
        {
            return this._numTxt.text;
        }

        public get nameStr(): string
        {
            return this._nameTxt.text;
        }

        /* internal */ /* var */_bg: ScaleBitmap;

        /* internal */ /* var */_numTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_getBtn: GButton;

        /* internal */ /* var */_exchangeBtn: GButton;

        /* internal */ /* var */_numChArr: Array<any>;

        /* internal */ /* var */_info: TOpenRechargeGiftBag;

        /* internal */ /* var */_pwidth: int=90;

        /* internal */ /* var */_nameBg: ScaleBitmap;

        /* internal */ /* var */_itemBg: ScaleBitmap;

        /* internal */ /* var */_isHadGet: Boolean;

        /* internal */ /* var */_glowYellow: Object /* flash.filters.GlowFilter */;

        /* internal */ /* var */_gradientGlow: Object /* flash.filters.GradientGlowFilter */;
    }
